package com.ruoyi.lhky.controller;

import com.ruoyi.lhky.pojo.StudyCompletion;
import com.ruoyi.lhky.service.StudyCompletionService;
import com.ruoyi.lhky.util.R;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/studyCompletion")
@Tag(name = "研究结束管理", description = "研究结束的相关操作")
public class StudySCompletionController {

    @Autowired
    private StudyCompletionService studyCompletionService;

    @PostMapping("/saveOrUpdate")
    @Operation(summary = "保存或更新研究结束记录", description = "根据testerId判断是否更新，否则新增")
    @ApiResponses({
            @ApiResponse(responseCode = "200", description = "保存成功"),
            @ApiResponse(responseCode = "400", description = "请求参数错误"),
            @ApiResponse(responseCode = "500", description = "服务器内部错误")
    })
    public R saveOrUpdateStudyCompletion(@RequestBody StudyCompletion studyCompletion) {
        return studyCompletionService.saveOrUpdateStudyCompletion(studyCompletion);
    }

    @GetMapping("/getByTesterId")
    @Operation(summary = "根据testerId获取研究结束记录", description = "获取指定testerId的研究结束记录")
    @ApiResponses({
            @ApiResponse(responseCode = "200", description = "获取成功"),
            @ApiResponse(responseCode = "400", description = "请求参数错误"),
            @ApiResponse(responseCode = "404", description = "记录不存在"),
            @ApiResponse(responseCode = "500", description = "服务器内部错误")
    })
    public R getStudyCompletionByTesterId(@RequestParam Long testerId) {
        return studyCompletionService.getStudyCompletionByTesterId(testerId);
    }
}
